import requests
from config import OLLAMA_API_KEY
import logging

# 设置日志
logger = logging.getLogger(__name__)

def polish_text(text):
    try:
        headers = {"Authorization": f"Bearer {OLLAMA_API_KEY}"}
        payload = {"text": text}
        response = requests.post("https://api.ollama.com/polish_text", headers=headers, json=payload)
        response.raise_for_status()

        polished = response.json()
        return polished['polished_text']
    except requests.exceptions.RequestException as e:
        logger.error(f"Text polishing failed: {e}")
        return None

# 调用函数
if __name__ == "__main__":
    polished_story = polish_text("这是一个示例故事")
    if polished_story:
        logger.info(f"Polished story: {polished_story}")
